package com.ruoyi.ofld.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ofld.domain.CarType;
import com.ruoyi.ofld.service.ICarTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆类型Controller
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/ofld/type")
public class CarTypeController extends BaseController
{
    @Autowired
    private ICarTypeService carTypeService;

    /**
     * 查询车辆类型列表
     */
    @PreAuthorize("@ss.hasPermi('ofld:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarType carType)
    {
        startPage();
        List<CarType> list = carTypeService.selectCarTypeList(carType);
        return getDataTable(list);
    }

    /**
     * 导出车辆类型列表
     */
    @PreAuthorize("@ss.hasPermi('ofld:type:export')")
    @Log(title = "车辆类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarType carType)
    {
        List<CarType> list = carTypeService.selectCarTypeList(carType);
        ExcelUtil<CarType> util = new ExcelUtil<CarType>(CarType.class);
        util.exportExcel(response, list, "车辆类型数据");
    }

    /**
     * 获取车辆类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('ofld:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(carTypeService.selectCarTypeById(id));
    }

    /**
     * 新增车辆类型
     */
    @PreAuthorize("@ss.hasPermi('ofld:type:add')")
    @Log(title = "车辆类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarType carType)
    {
        return toAjax(carTypeService.insertCarType(carType));
    }

    /**
     * 修改车辆类型
     */
    @PreAuthorize("@ss.hasPermi('ofld:type:edit')")
    @Log(title = "车辆类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarType carType)
    {
        return toAjax(carTypeService.updateCarType(carType));
    }

    /**
     * 删除车辆类型
     */
    @PreAuthorize("@ss.hasPermi('ofld:type:remove')")
    @Log(title = "车辆类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(carTypeService.deleteCarTypeByIds(ids));
    }
}
